package game;

import java.util.ArrayList;
import java.util.Collections;

public class PokerGame01 {
    //静态代码块
    //特点：随着类的加载而在加载的，而且只执行一次。
    //牌盒
    //♥3 ♣3
    static ArrayList<String> list = new ArrayList<>();

    static {
        // 准备牌
        // "♦", "♣", "♥", "♠"
        // "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"
        String[] color = {"♦", "♣", "♥", "♠"};
        String[] number = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        for (String c : color) {
            //c依次表示每一种花色
            for (String n : number) {
                //n 依次表示每一个数字
                list.add(c + n);
            }
        }
        list.add("小王");
        list.add("大王");
    }

    public PokerGame01() {

        //洗牌
        Collections.shuffle(list);
        //发牌
        ArrayList<String> dizu = new ArrayList<>();
        ArrayList<String> player1 = new ArrayList<>();
        ArrayList<String> player2 = new ArrayList<>();
        ArrayList<String> player3 = new ArrayList<>();
        //遍历牌盒得到每一张牌
        for (int i = 0; i < list.size(); i++) {
            String poke = list.get(i);
            //前三张发给底牌(地主的牌)
            if (i <= 2) {
                dizu.add(poke);
                continue;
            }
            //给三个玩家轮流发牌
            if (i % 3 == 0) {
                player1.add(poke);
            } else if (i % 3 == 1) {
                player2.add(poke);
            } else {
                player3.add(poke);
            }

        }
        //看牌
        lookPoker("周润发", player1);
        lookPoker("刘德华", player2);
        lookPoker("周星驰", player3);
        lookPoker("底牌", dizu);
    }

    /*
     * 参数一：玩家的名字
     * 参数二：每位玩家的牌
     * */
    public void lookPoker(String name, ArrayList<String> list) {
        System.out.print(name + ": ");
        for (String poke : list) {
            System.out.print(poke + " ");
        }
        System.out.println();
    }
}
